<?php
namespace app\admin\controller;
use app\admin\controller\Permissions;
use app\admin\model\Kxffhz as kxffhzModel;
use think\Config;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
class Anzhi extends Permissions
{

    public function xy()
    {
        $list = db('population')->where(['isdel'=>1])->select();
        foreach ($list as $k => &$v) {
            $info = db('xieyianzhi')->where(['pid'=>$v['id']])->find();
            $allMoney1 = bcadd($info['ydmoney'],$info['pjmoney'],2);
            $allMoney2 = bcadd($allMoney1,$info['bzfmoney'],2);
            $allMoney3 = bcadd($allMoney2,$info['tcwmoney'],2);
            $allMoney = bcadd($allMoney3,$info['dxmoney'],2);
            $v['ffmoney']= $allMoney?$allMoney:0;
        }
        $this->assign('list',$list);
        return $this->fetch();
    }

    public function info(){
        $id = input('id');

        $this->assign('id',$id);
        $zhu = db('population')->where(['id'=>$id])->find();

        $info = db('xieyianzhi')->where(['pid'=>$id])->find();
        $this->assign('info',$info);


        $allMoney1 = bcadd($info['ydmoney'],$info['pjmoney'],2);
        $allMoney2 = bcadd($allMoney1,$info['bzfmoney'],2);
        $allMoney3 = bcadd($allMoney2,$info['tcwmoney'],2);
        $allMoney = bcadd($allMoney3,$info['dxmoney'],2);
        $this->assign('allMoney',$allMoney);

        if (request()->isAjax()) {
            $input = input('post.');
            $pid = $input['uid'];
            unset($input['uid']);
            unset($input['allMoney']);
            $arr = [];
            $onlineInfo = db('xieyianzhi')->where(['pid'=>$pid])->find();
            if($onlineInfo['id']){
                $isok = db('xieyianzhi')->where('id',$onlineInfo['id'])->update($input);
            }else{
                $isok = db('xieyianzhi')->insert($input);
            }
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $this->assign('zhu',$zhu);
        $admin_cate_id = Session::get('admin_cate_id');
        $this->assign('admin_cate_id',$admin_cate_id);
        $operation = Config::get('operation');
        $this->assign('operation',$operation);
        return $this->fetch();
    }
}
